<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="ctp-tag" prefix="ctp"%>
<%@ page import="com.icbc.cte.base.*"%>
<%@page import="com.icbc.ssic.base.Credentials"%>
<%@page import="com.icbc.ssic.base.SSICUser"%>
<% 	
	String ssicFlag=request.getParameter("ssicFlag");
	if("1".equals(ssicFlag)){
		Credentials cred=null;
		SSICUser user=null;
		Object obj=null;
		obj=request.getAttribute("ssiCredentials");
		boolean isSsicAuth=false;
		if(obj!=null){
			cred=(Credentials)obj;
			user=cred.getSSICUser();
			String userName=user.getUserName();
			String userName1=request.getParameter("userId");
			if(userName!=null&&userName.equals(userName1)){
				isSsicAuth=true;
			}
		}
		if(!isSsicAuth){
			request.getRequestDispatcher("/index.jsp").forward(request,response);	
		}
	}
	//配合安全改造
	String pwdChangePeriod;
	String webMode;
	try {
		pwdChangePeriod = CTEConstance.getEnvProperty("pwdChangePeriod");
		webMode = CTEConstance.getEnvProperty("webMode");
	} catch (Exception e) {
		webMode = "standard";
		pwdChangePeriod = "90";
	}
	if(null == webMode || "".equals(webMode)){
		webMode = "standard";
	}
	if(null == pwdChangePeriod || "".equals(pwdChangePeriod)){
		pwdChangePeriod = "90";
	}
%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>垂直两栏结构</title>
        <ctp:include items="borderlayout,accordion,messagebox" />
        <link href="<ctp:out name='fullPath'/>css/menu_tree.css" rel="stylesheet" type="text/css" />
        <link href="<ctp:out name='fullPath'/>css/skins/standard/mainframe_v.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="<ctp:out name='fullPath'/>js/leftmenu.js">
        </script>
        <script type="text/javascript" src="<ctp:out name='fullPath'/>js/changeskins.js">
        </script>
        <!--对角色相关的变量进行赋值  start -->
        <ctp:iterator name="sessCtx.roleList" var="role">
            <ctp:set name="roleId" value="role.id" />
            <ctp:if test="$index==0">
                <ctp:if test="sessCtx.defaultRoleId==null || sessCtx.defaultRoleId==''">
                    <ctp:set name="currentroleId" value="roleId" />
                </ctp:if>
                <ctp:else>
                    <ctp:set name="currentroleId" value="sessCtx.defaultRoleId" />
                </ctp:else>
            </ctp:if>
        </ctp:iterator><!--对角色相关的变量进行赋值  end -->
        <script type="text/javascript">
            var centerBorderlayout, mainBorderLayout, accordionPanel, menuContent, shortcutFlag = 0, collapseFlag = 0, ctpStatusBar, statusbar, unloadflag = true;
            var pwdChangePeriod = "<%=pwdChangePeriod %>";
            var ssicFlag = '<ctp:out name="sessCtx.ssicFlag"/>';
            
            $(window).bind({
                'load': init,
                'unload': function(){
					if (unloadflag) {
						try {
							ctp.data.getJSON('<ctp:url href="signoff.opg"/>');
						} catch (e) {
						//屏蔽了超时时关闭页面导致抛出错误的问题
						}
					}
                }
            });
            
            //页面初始化
            function init(){
            
                //IE6图片缓存问题
                try {
                    document.execCommand('BackgroundImageCache', false, true);
                } catch (e) {
                }
                
                //为全局变量状态条新建对象
                window.ctpStatusBar = new ctp.ui.statusbar({
                    isVisible: false,
                    renderTo: 'body'
                });
                top.statusbar = top.ctpStatusBar = window.ctpStatusBar;
                
                //初始化页面布局
                layoutInit();
                
                //缓存top层变量
                top.ctpMSB = ctpMSB;
                top.setFont = setFont;
                
                //添加菜单
                menuContent = $('#menutree').contents().find('body');
                $('#section_1').append(menuContent.html());
                
                //添加常用菜单
                var shortcut = $('#menutree').contents().find('#Shortcut_menu');
                
                if (shortcut.size()) {
                    shortcutFlag = 1;
                    shortcut.find('.collapsed-1').removeClass('collapsed-1');
                    shortcut.find('span').first().removeClass("t-minus").addClass("l-minus");
                    shortcut.find('span').first().attr('node', 'last');
                    var shortcutHtml = shortcut.html();
                    shortcutHtml = "<div class='menu-body' onclick='menuShow(event)'><ul><li class='L1'>" + shortcutHtml + "</li></ul></div>";
                    $('#section_2').html(shortcutHtml);
                }
                //添加Accordion Panel
                accordionPanel = new ctp.ui.accordion({
                    renderTo: mainBorderLayout.panes.west,//"accordion",
                    autoWidth: true,
                    autoHeight: true,
                    active: 1,
                    type: 'menu',
					collapsible: false,
                    items: [{
                        title: '<ctp:label key="ctp-menumsg-001" />',
                        items: ["section_2"],
                        button: '<ctp:label key="main.set" />',
                        buttonOnClick: function(){
                            submit(null, 'personal.flowc?flowActionName=defineShortCutMenu', '2', '<ctp:label key="main.define_common_menu" />')
                        }
                    }, {
                        title: '<ctp:label key="ctp-menumsg-003" />',
                        items: ['section_1'],
                        button: '<ctp:label key="main.collapse" />',
                        buttonOnClick: collapseNode
                    }]
                });
                //accordionPanel.resize();
                accordionPanel.setHeight(mainBorderLayout.panes.west.height());
                
                $('#textbutton').bind('click', function(){
                    mainBorderLayout.close('north');
                    mainBorderLayout.close('south');
                });
				 $('.L21 > a').click(function(){
					var spanClass = $(this).children().attr("class");
					if (spanClass != "t-plus") {
						$(this).children().attr("class", "t-plus");
						$(this).parent().find("ul").css("display", "none");	
						accordionPanel.resize();					
					} else {
						$(this).children().attr("class", "t-minus");
						$(this).parent().find("ul").css("display", "block");	
						accordionPanel.resize();					
					}
				});

				//配合安全改造
	            var currUserLstModPwdTime = '<ctp:out name="sessCtx.user.lstModPwdTime"/>';
                var currUserPwdIsReseted = '<ctp:out name="sessCtx.user.pwdIsReseted"/>';

                var alertMsg;
                var moreThanPeriod = moreThanPwdChangePeriod(currUserLstModPwdTime, pwdChangePeriod);
                if(currUserPwdIsReseted === '1'){
                	alertMsg = '<ctp:label key="pwd_is_reseted" />';//系统检测到您是首次登录或密码经过重置，请点击“确定”修改密码，否则无法继续操作系统，并将退出系统。
                }else if(moreThanPeriod){
                    alertMsg = '<ctp:label key="more_than_change_period1" />'//系统检测到您已经超过 
                        + pwdChangePeriod 
                    	+ '<ctp:label key="more_than_change_period2" />';//天没有修改密码，请点击“确定”修改密码，否则无法继续操作系统，并将退出系统。
                }
                //pwdChangePeriod
                if(currUserPwdIsReseted === '1' || moreThanPeriod){
                    //用户密码经过重置或首次登录，强制用户修改密码
                    ctpMSB.alert({
                        message: alertMsg,
                        handler: function(tp){
                            if(tp === 'ok'){
                            	ctpMSB.win({
                            		title: '<ctp:label key="change_password"/>',//修改密码
                                    message: '<ctp:url href="changepassword.flowc" flowActionName="changepassword" />',
                                    width: '500px',
                                    height: '250px',
                                    iframe: true,
                                    handler: function(tp){
                                        if(tp === 'close'){
                                        	ctpMSB.alert({
                                            	title: '<ctp:label key="operation_tips"/>',//操作提示
                                            	message: '<ctp:label key="do_not_change_password"/>', //您没有修改密码，无法继续操作系统，并将退出系统。
                                            	handler: function(tp){
                                            		signOff_submit('0', 'signOut');//如果不更改密码，则签退
                                            	}
                                        	});
                                        }
                                    }
                                });
                            }else{
                            	ctpMSB.alert({
                            		title: '<ctp:label key="operation_tips"/>',//操作提示
                                	message: '<ctp:label key="do_not_change_password"/>', //您没有修改密码，无法继续操作系统，并将退出系统。 
                                	handler: function(tp){
                                		signOff_submit('0', 'signOut');//如果不更改密码，则签退
                                	}
                            	});
            				}
                        }
                    });
                }
            };
            
            //初始化页面布局
            function layoutInit(){
                
                centerBorderlayout = new ctp.ui.borderlayout({
                    id: 'centerBorderlayout',
                    type: '2E',
                    north__resizable: false,
                    north__spacing_open: 0,
                    north__size: 35,
                    north__items: ['main_header'],
                    center__items: ['main_center']
                });
                
                mainBorderLayout = new ctp.ui.borderlayout({
                    id: 'mainBorderLayout',
                    type: "4I",
                    north__resizable: false,
                    north__size: 62,
                    north__spacing_open: 0,
                    north__items: ['header_Top'],
                    west__size: 200,
                    west__contentPadding: '6px 0 0 0',
                    south__size: 23,
                    south__resizable: false,
                    south__spacing_open: 0,
                    south__items: ['footer'],
                    center__items: [centerBorderlayout],
                    onResize: function(pname, ele, stat, popt, lname){
                        if (pname == "west") {
                            if (accordionPanel) {
                                accordionPanel.resize();
                                accordionPanel.setHeight(mainBorderLayout.panes.west.height());
                            }
                        }
                    },
                    renderTo: 'body'
                });
            }

          	//配合安全改造：检查上一次密码修改日期距今是否超过密码修改周期
            function moreThanPwdChangePeriod(currUserLstModPwdTime, pwdChangePeriod){
                var today = new Date();
                var year = today.getFullYear();
                var month = today.getMonth() + 1;
                var date = today.getDate();
                var todayStr = year + '/' + (month > 10 ? month : '0' + month) + '/' + (date > 10 ? date : '0' + date);
                var now = new Date(todayStr);
                var nowMillisecond = now.getTime();
                pwdChangePeriod_ms = parseInt(pwdChangePeriod)*24*60*60*1000;
                var period = nowMillisecond - pwdChangePeriod_ms;//计算出改密码周期前的毫秒数 
                var dateBeforepwdChangePeriod = new Date(period);//当前日期到改密码周期之间的毫秒数
                year = dateBeforepwdChangePeriod.getFullYear();
                month = dateBeforepwdChangePeriod.getMonth() + 1;
                date = dateBeforepwdChangePeriod.getDate();
                //获得
                dateBeforepwdChangePeriodStr = year + (month > 10 ? month : '0' + month) + (date > 10 ? date : '0' + date);

                if(currUserLstModPwdTime > dateBeforepwdChangePeriodStr){
                    //上一次修改日期比改密码周期前要大，即还在周期内
                    return false;
                }else{
                    //周期外
                    return true;
                }
            }
            
            function collapseNode(){
                //展开
                if (collapseFlag === 0) {
                    hideAll('L1');
                    accordionPanel.resize();
                    accordionPanel.changeButtonText(1, '<ctp:label key="main.spread" />');
                    collapseFlag = 1;
                }
                //折叠
                else if (collapseFlag === 1) {
                    showAll('L1');
                    accordionPanel.resize();
                    accordionPanel.changeButtonText(1, '<ctp:label key="main.collapse" />');
                    collapseFlag = 0;
                }
            }
            
            //fontSize为 数值，字体 大小数字，height为 高度 数值，textAlign可以设置为"left","right","center";
            //例如：breadcrumbStyle(16,24,"center");表示字体大小为 16Px，高度 为 24px，居中对齐
            function breadcrumbStyle(fontSize, height, textAlign){
                var bcs = $('#main_header div');
                bcs.css({
                    "font-size": fontSize + "px",
                    "height": height + "px",
                    "text-align": textAlign
                });
            }
            
            //top.setFont("xxx");用来设置功能标题区里的文字
            function setFont(text){
                $('#main_header .breadcrumb_nav').text(text);
            }
            
            //签退操作
            function signOff_submit(flag, siteOperationName){
				unloadflag = false;
                document.signOffForm.siteOperationName.value = siteOperationName;
                if (flag == '0') {
                    document.signOffForm.flowActionName.value = "signOut";
                }
                else {
                    document.signOffForm.flowActionName.value = "exit";
                }
                document.signOffForm.submit();
            }
        </script>
    </head>
    <body>
        <!--div id="header"-->
        <div id="header_Top" class="header">
            <div id="header_left" class="headerleft">
                <div class="logo">
                </div>
                <div id="headerSystemName" class="systemname">
                    <ctp:label key="main.title" />
                </div>
            </div>
            <div id="header_right" class="headerright">
                <a class="User"><span><ctp:out name='sessCtx.user.branchName' /></span><span>，</span><span><ctp:out name='sessCtx.user.name' /></span></a><a class="Help" href="#"><span><ctp:label key="main.help" /></span></a><a id='textbutton' title='<ctp:label key="main.collapseHeaderFooter" />' class="textbutton Scaling"><span><span><span>&nbsp;</span></span></span></a>
                <ctp:if test="sessCtx.ssicFlag eq 1">
                    <a class="textbutton Quit" href="javascript:signOff_submit('1','signOutSSI');">
                </ctp:if>
                <ctp:else>
                <a class="textbutton Quit" href="javascript:signOff_submit('0', 'signOut');">
                </ctp:else>
                <span><span><ctp:label key="main.logout" /></span></span></a>
        </div>
        </div>
        <!--/div-->
        <iframe id='menutree' style="display:none" src='<ctp:url href="getlogonmenu.flowc?flowActionName=process0" params="userId=sessCtx.user.id;defaultRoleId=currentroleId;Language=sessCtx.Language;fullpath=fullPath;menuType=\"menu\"" />'>
        </iframe>
        <!--div id="main" class="ctp-mainframe-bg" style="height: 100%; line-height: 100%;"-->
        <div id="main_header" class="breadcrumb_box">
            <div class="breadcrumb_nav">
                <ctp:label key="BS_flag_introduce" />
            </div>
            <div id='sysTime'>
                <ctp:dateFmt style="long"/>
            </div>
        </div>
        <div id="main_center">
            <iframe id="mainContent" MARGINHEIGHT="0" MARGINWIDTH="0" FRAMEBORDER="0" width="100%" height="100%" SCROLLING="auto" SRC="<ctp:url href="getlogonmenu.flowc" flowActionName="introduction" />">
            </iframe>
        </div>
        <!--/div-->
        <div id="left">
            <div id="section_1">
            </div>
            <div id="section_2">
            </div>
        </div>
        <div id="footer" class="footer">
            <div id="version" class="footer_version">
                <ctp:label key="copyright" />
            </div>
            <div id="logonTime" class="footer_logonTime">
            </div>
        </div>
        <input id="sessionId" type="hidden" value="<ctp:out name='sessCtx.dse_sessionId' />" /><input id="fullPath" type="hidden" value="<ctp:out name='fullPath' />" /><input id="Language" type="hidden" value="<ctp:out name='sessCtx.Language' />" />
        <ctp:form name="signOffForm" method="post" action="signoff.flowc" flowActionName="signOut">
            <ctp:hidden name="siteOperationName" />
        </ctp:form>
    </body>
</html>